//
//  MSBusinessReporController.m
//  觅尚
//
//  Created by No.8 on 2019/4/7.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSBusinessReporController.h"
#import "MSHomeCell.h"

@interface MSBusinessReporController ()<UITableViewDelegate,UITableViewDataSource>
//通用导航栏
{
    CustomNavigationBar *naviagtionBar;
    
}
/** 表视图*/
@property(nonatomic,strong)UITableView *tableView;

/** 表视图*/
@property(nonatomic,strong)UIView *HeaderView;


/** 取反*/
@property(nonatomic,strong)UIButton *typeButton;

/** 遮盖层*/
@property(nonatomic,strong)UIView *backView;


/** 弹出View*/
@property(nonatomic,strong)UIView *showView;

/** 今日收益*/
@property(nonatomic,strong)UILabel *Titlelabel;


@end

@implementation MSBusinessReporController

/** Nav实现 */
- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
    self.view.backgroundColor = backgroundcolor;
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self ReloadData];
        
    });
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self CreateNavigationBar];
    
    [self CreatView];
    
    [self tableView];
}
- (void)CreatView{
    
    UIButton * completeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, ScreenHeight - 120 * px, ScreenWidth, 120 * px)];
    [completeButton setTitle:@"上报" forState:UIControlStateNormal];
    completeButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [completeButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
    [completeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [completeButton addTarget:self action:@selector(PlayButtonClick) forControlEvents:UIControlEventTouchUpInside];
    //    [completeButton addTarget:self action:@selector(playCardButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:completeButton];
}

- (void)ReloadData{
    
    NSDictionary * params = @{@"busId":[WYCAccountTool unarchivebelongBusid]};
    [HTTPRequest POST:MSgetOtherIncome params:params succeed:^(id responseObject) {
        WYCLog(@"responseObject==========%@",responseObject);
        WYCLog(@"responseObject==========%@",responseObject[@"data"][@"sumOtherMoney"]);
        if (CodeStr) {
            self.Titlelabel.text = [NSString stringWithFormat:@"今日收益:￥%@",responseObject[@"data"][@"sumOtherMoney"]];
            WYCLog(@"responseObject==========%@",self.Titlelabel.text);
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 5;
}

//返回每组头部view

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headerView = [[UIView alloc]init];
    
    headerView.backgroundColor = WYCRGBColor(20, 33, 48);
    
    
    //图片
    UIImageView *CheckIMG = [[UIImageView alloc] initWithFrame:CGRectMake(60 * px, 45 * px, 30 * px, 30 * px)];
    CheckIMG.layer.cornerRadius = 15 * px;
    CheckIMG.backgroundColor = [UIColor redColor];
    CheckIMG.layer.masksToBounds = YES;
    [headerView addSubview:CheckIMG];
    
    
    //标题
    UILabel * Titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(CheckIMG.frame) + 10 * px, 25 * px, ScreenWidth / 2, 60 * px)];
    Titlelabel.textColor = [UIColor whiteColor];
    Titlelabel.textAlignment = NSTextAlignmentLeft;
    Titlelabel.font = [UIFont boldSystemFontOfSize:SYRealValue(28 / 2)];
    [headerView addSubview:Titlelabel];
    
    
    
//    self.Titlelabel = Totlelabel ;
    
    
    
    
    //详情按钮
    UIButton * detailedButton = [[UIButton alloc] initWithFrame:CGRectMake( ScreenWidth - 270 * px, Titlelabel.y, Titlelabel.width, Titlelabel.height)];
    //设置边框的颜色
    [detailedButton.layer setBorderColor:WYCRGBColor(80, 112, 148).CGColor];
    detailedButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    //设置边框的粗细
    detailedButton.hidden = YES;
    [detailedButton.layer setBorderWidth:1.0];
    [detailedButton setTitleColor:WYCRGBColor(59, 84, 112) forState:UIControlStateNormal];
    detailedButton.layer.cornerRadius = detailedButton.height * 0.5;
    [headerView addSubview:detailedButton];
    
    
    
    if (section == 0) {
        
//        self.Titlelabel.text = @"今日收益:￥500";
        self.Titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(CheckIMG.frame) + 10 * px, 25 * px, ScreenWidth / 2, 60 * px)];
        self.Titlelabel.textColor = [UIColor whiteColor];
        self.Titlelabel.textAlignment = NSTextAlignmentLeft;
        self.Titlelabel.font = [UIFont boldSystemFontOfSize:SYRealValue(28 / 2)];
        [headerView addSubview:self.Titlelabel];
        Titlelabel.hidden = YES;
        
    }else if (section == 1) {
        
        Titlelabel.text = @"会员卡";
        
    }else if (section == 2) {
        Titlelabel.text = @"挂账";
        
    }else if (section == 3) {
        Titlelabel.text = @"招待";
        
    }else {
        Titlelabel.text = @"其他";
    }
    
    return headerView;
    
}

// 返回组头部view的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 130 * px;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 4;
    }else if (section == 1 || section == 2) {
        return 2;
    }else {
        return 1;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 130 * px;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    MSHomeCell * cell = [MSHomeCell cellWithTableView:tableView];
    tableView.backgroundColor = [UIColor clearColor];
    //无色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0){
            /** 微信*/
            UILabel * WeichatTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            WeichatTitle.textColor = [UIColor whiteColor];
            WeichatTitle.text = @"微信";
            WeichatTitle.textAlignment = NSTextAlignmentLeft;
            WeichatTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:WeichatTitle];
            
            
            /** 微信*/
            UILabel * WeichatLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, WeichatTitle.y, ScreenWidth / 2 - 80 * px, WeichatTitle.height)];
            WeichatLabel.textColor = ShallowGreenColor;
            WeichatLabel.text = @"￥2000";
            WeichatLabel.textAlignment = NSTextAlignmentRight;
            WeichatLabel.font = WeichatTitle.font;
            [cell.contentView addSubview:WeichatLabel];
        }else if (indexPath.row == 1){
            /** 微信*/
            UILabel * AlipayTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            AlipayTitle.textColor = [UIColor whiteColor];
            AlipayTitle.text = @"支付宝";
            AlipayTitle.textAlignment = NSTextAlignmentLeft;
            AlipayTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:AlipayTitle];
            
            
            /** 微信*/
            UILabel * AlipayLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, AlipayTitle.y, ScreenWidth / 2 - 80 * px, AlipayTitle.height)];
            AlipayLabel.textColor = ShallowGreenColor;
            AlipayLabel.text = @"￥2000";
            AlipayLabel.textAlignment = NSTextAlignmentRight;
            AlipayLabel.font = AlipayTitle.font;
            [cell.contentView addSubview:AlipayLabel];
        }else if (indexPath.row == 2){
            /** 微信*/
            UILabel * CashTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            CashTitle.textColor = [UIColor whiteColor];
            CashTitle.text = @"现金";
            CashTitle.textAlignment = NSTextAlignmentLeft;
            CashTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:CashTitle];
            
            
            /** 微信*/
            UILabel * CashLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, CashTitle.y, ScreenWidth / 2 - 80 * px, CashTitle.height)];
            CashLabel.textColor = ShallowGreenColor;
            CashLabel.text = @"￥2000";
            CashLabel.textAlignment = NSTextAlignmentRight;
            CashLabel.font = CashTitle.font;
            [cell.contentView addSubview:CashLabel];
        }else {
            /** 微信*/
            UILabel * CashTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            CashTitle.textColor = [UIColor whiteColor];
            CashTitle.text = @"刷卡";
            CashTitle.textAlignment = NSTextAlignmentLeft;
            CashTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:CashTitle];
            
            
            /** 微信*/
            UILabel * PayCardLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, CashTitle.y, ScreenWidth / 2 - 80 * px, CashTitle.height)];
            PayCardLabel.textColor = ShallowGreenColor;
            PayCardLabel.text = @"￥2000";
            PayCardLabel.textAlignment = NSTextAlignmentRight;
            PayCardLabel.font = CashTitle.font;
            [cell.contentView addSubview:PayCardLabel];
        }
    }else if (indexPath.section == 1) {
        if (indexPath.row == 0){
            /** 微信*/
            UILabel * AccountTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            AccountTitle.textColor = [UIColor whiteColor];
            AccountTitle.text = @"充值入账";
            AccountTitle.textAlignment = NSTextAlignmentLeft;
            AccountTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:AccountTitle];
            
            
            /** 微信*/
            UILabel * AccountLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, AccountTitle.y, ScreenWidth / 2 - 80 * px, AccountTitle.height)];
            AccountLabel.textColor = ShallowGreenColor;
            AccountLabel.text = @"￥2000";
            AccountLabel.textAlignment = NSTextAlignmentRight;
            AccountLabel.font = AccountTitle.font;
            [cell.contentView addSubview:AccountLabel];
        }else {
            /** 微信*/
            UILabel * ConsumptionTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            ConsumptionTitle.textColor = [UIColor whiteColor];
            ConsumptionTitle.text = @"消费入账";
            ConsumptionTitle.textAlignment = NSTextAlignmentLeft;
            ConsumptionTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:ConsumptionTitle];
            
            
            /** 微信*/
            UILabel * ConsumptionLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, ConsumptionTitle.y, ScreenWidth / 2 - 80 * px, ConsumptionTitle.height)];
            ConsumptionLabel.textColor = ShallowGreenColor;
            ConsumptionLabel.text = @"￥2000";
            ConsumptionLabel.textAlignment = NSTextAlignmentRight;
            ConsumptionLabel.font = ConsumptionTitle.font;
            [cell.contentView addSubview:ConsumptionLabel];
        }
    }else if (indexPath.section == 2) {
        if (indexPath.row == 0){
            /** 微信*/
            UILabel * EntryTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            EntryTitle.textColor = [UIColor whiteColor];
            EntryTitle.text = @"挂账还款入账";
            EntryTitle.textAlignment = NSTextAlignmentLeft;
            EntryTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:EntryTitle];
            
            
            /** 微信*/
            UILabel * EntryLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, EntryTitle.y, ScreenWidth / 2 - 80 * px, EntryTitle.height)];
            EntryLabel.textColor = ShallowGreenColor;
            EntryLabel.text = @"￥2000";
            EntryLabel.textAlignment = NSTextAlignmentRight;
            EntryLabel.font = EntryTitle.font;
            [cell.contentView addSubview:EntryLabel];
        }else {
            /** 微信*/
            UILabel * SettleTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            SettleTitle.textColor = [UIColor whiteColor];
            SettleTitle.text = @"挂账金额";
            SettleTitle.textAlignment = NSTextAlignmentLeft;
            SettleTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:SettleTitle];
            
            
            /** 微信*/
            UILabel * SettleLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, SettleTitle.y, ScreenWidth / 2 - 80 * px, SettleTitle.height)];
            SettleLabel.textColor = ShallowGreenColor;
            SettleLabel.text = @"￥2000";
            SettleLabel.textAlignment = NSTextAlignmentRight;
            SettleLabel.font = SettleTitle.font;
            [cell.contentView addSubview:SettleLabel];
        }
    }else if (indexPath.section == 3){
        
            /** 微信*/
            UILabel * EntertainTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            EntertainTitle.textColor = [UIColor whiteColor];
            EntertainTitle.text = @"招待";
            EntertainTitle.textAlignment = NSTextAlignmentLeft;
            EntertainTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:EntertainTitle];
        
        
            /** 微信*/
            UILabel * EntertainLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, EntertainTitle.y, ScreenWidth / 2 - 80 * px, EntertainTitle.height)];
            EntertainLabel.textColor = ShallowGreenColor;
            EntertainLabel.text = @"￥2000";
            EntertainLabel.textAlignment = NSTextAlignmentRight;
            EntertainLabel.font = EntertainTitle.font;
            [cell.contentView addSubview:EntertainLabel];
        
    } else{
        
            /** 微信*/
            UILabel * OtherTitle = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 35 * px, 300 * px, 60 * px)];
            OtherTitle.textColor = [UIColor whiteColor];
            OtherTitle.text = @"其他";
            OtherTitle.textAlignment = NSTextAlignmentLeft;
            OtherTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:OtherTitle];
        
        
            /** 微信*/
            UILabel * OtherLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, OtherTitle.y, ScreenWidth / 2 - 80 * px, OtherTitle.height)];
            OtherLabel.textColor = ShallowGreenColor;
            OtherLabel.text = @"￥2000";
            OtherLabel.textAlignment = NSTextAlignmentRight;
            OtherLabel.font = OtherTitle.font;
            [cell.contentView addSubview:OtherLabel];
    }
    return cell;
}

/** 表视图*/
- (UITableView *)tableView{
    self.extendedLayoutIncludesOpaqueBars = YES;
    if (!_tableView) {
        
        if (@available(iOS 11.0, *)) {
            
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        } else {
            
            self.automaticallyAdjustsScrollViewInsets = NO;
            
        }
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, [self navBarBottom], ScreenWidth, ScreenHeight - [self navBarBottom] - 120 * px) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
//        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.separatorColor = BackViewColor;
        [self.view addSubview:self.tableView];
    }
    return _tableView;
}

- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"营业数据上报";
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:NO];
}



- (void)PlayButtonClick{
    
    
    UIView * view = [[UIView alloc] init];
    view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [[UIApplication sharedApplication].keyWindow  addSubview:view];
    self.backView = view;
    
    
    UIView * showView = [[UIView alloc] init];
    showView.frame = CGRectMake(100 * px, ScreenHeight / 4, ScreenWidth - 200 * px, ScreenHeight / 2 - 100 * px);
    showView.backgroundColor = [UIColor whiteColor];
    showView.layer.cornerRadius = 20 * px;
    [view addSubview:showView];
    self.showView = showView;
    
    
    /** 标题*/
    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 80 * px, showView.width, 60 * px)];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.text = @"上报";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont boldSystemFontOfSize:SYRealValue(35 / 2)];
    [showView addSubview:titleLabel];
    
    
    
    /** 标题*/
    UILabel * timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(40 * px, CGRectGetMaxY(titleLabel.frame) + 100 * px, 250 * px, 80 * px)];
    timeLabel.textColor = [UIColor blackColor];
    timeLabel.text = @"项目名称:";
    timeLabel.textAlignment = NSTextAlignmentLeft;
    timeLabel.font = [UIFont systemFontOfSize:SYRealValue(32 / 2)];
    [showView addSubview:timeLabel];
    
    
    UITextField * timeField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(timeLabel.frame) + 20 * px, timeLabel.y, showView.width - 410 * px, titleLabel.height)];
    timeField.placeholder = @"2019.03.22";
    [timeField setValue:[UIFont systemFontOfSize:SYRealValue(32 / 2)] forKeyPath:@"_placeholderLabel.font"];
    timeField.backgroundColor = [UIColor clearColor];
    timeField.textColor = [UIColor blackColor];
    [showView addSubview:timeField];
    
    
    UIView * timeLinView = [[UIView alloc] init];
    timeLinView.frame = CGRectMake(timeLabel.x, CGRectGetMaxY(timeField.frame) + 20 * px, showView.width - 80 * px, 1);
    timeLinView.backgroundColor = DividinglineColor;
    [showView addSubview:timeLinView];
    
    
    
    /** 标题*/
    UILabel * CardNMLabel = [[UILabel alloc] initWithFrame:CGRectMake(timeLabel.x, CGRectGetMaxY(timeLinView.frame) + 80 * px, timeLabel.width, timeLabel.height)];
    CardNMLabel.textColor = timeLabel.textColor;
    CardNMLabel.text = @"收益总额:";
    CardNMLabel.textAlignment = timeLabel.textAlignment;
    CardNMLabel.font = timeLabel.font;
    [showView addSubview:CardNMLabel];
    
    
    UITextField * CardNMField = [[UITextField alloc] initWithFrame:CGRectMake(timeField.x, CardNMLabel.y, timeField.width, timeField.height)];
    CardNMField.text = @"32222233";
    CardNMField.textAlignment = NSTextAlignmentRight;
    CardNMField.backgroundColor = timeField.backgroundColor;
    CardNMField.textColor = timeField.textColor;
    [showView addSubview:CardNMField];
    
    
    UIView * CardNMLinView = [[UIView alloc] init];
    CardNMLinView.frame = CGRectMake(timeLinView.x, CGRectGetMaxY(CardNMField.frame) + 20 * px, timeLinView.width, timeLinView.height);
    CardNMLinView.backgroundColor = DividinglineColor;
    [showView addSubview:CardNMLinView];
    
    
    
    UIButton * completeButton = [[UIButton alloc] initWithFrame:CGRectMake(30 * px, CGRectGetMaxY(CardNMLinView.frame) + 100 * px, showView.width - 60 * px, 120 * px)];
    [completeButton setTitle:@"完成" forState:UIControlStateNormal];
    completeButton.layer.cornerRadius = 60 * px;
    completeButton.layer.masksToBounds = YES;
    completeButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [completeButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
    [completeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [completeButton addTarget:self action:@selector(completeButtonClick) forControlEvents:UIControlEventTouchUpInside];
    //    [completeButton addTarget:self action:@selector(playCardButton) forControlEvents:UIControlEventTouchUpInside];
    [showView addSubview:completeButton];
    
}

- (void)completeButtonClick{
    
    [self.backView removeFromSuperview];
}
@end
